* The analysis was conducted using Stata 16. 
clear
* Change directory to where the folder with the data is
cd "Data Archive TWT Predictions\DSBC"

*Merge EU predictions
use PredEURUMCARA, clear
append using PredEURUMCRRA
append using PredEURPMCARA
append using PredEURPMCRRA

*Merge TWT predictions
append using propcorrpredNoTimePressureBars
append using propcorrpredNoTimePressurePie
append using propcorrpredTimePressureBars
append using propcorrpredTimePressurePie

collapse corrpredTWTYesP_Bars corrpredTWTNoP_Bars corrpredTWTYesP_Pies corrpredTWTNoP_Pies corrpredCARA corrpredCRRA  corrpredRPMCARA corrpredRPMCRRA, by(subj)

gen corrpredTWT=(corrpredTWTYesP_Bars+corrpredTWTNoP_Bars+corrpredTWTYesP_Pies+corrpredTWTNoP_Pies)/4

*Summarize and test
sum corrpredTWT corrpredCARA corrpredCRRA corrpredRPMCARA corrpredRPMCRRA, detail
signrank  corrpredCRRA = corrpredTWT
signrank  corrpredCARA = corrpredTWT
signrank  corrpredRPMCRRA = corrpredTWT
signrank  corrpredRPMCARA = corrpredTWT

*Product Figure 2 Left
preserve
gen G =_n
sum  corrpredTWT, detail
gen graphEPV = r(mean)*100 if G==1
ci mean corrpredTWT, level(95)
gen low = r(lb)   if G==1
gen high = r(ub)  if G==1
sum corrpredCRRA, detail
replace graphEPV = r(mean)*100 if G==3
ci mean corrpredCRRA, level(95)
replace low = r(lb)   if G==3
replace high = r(ub)  if G==3
sum corrpredCARA, detail
replace graphEPV = r(mean)*100 if G==5
ci mean corrpredCARA, level(95)
replace low = r(lb)   if G==5
replace high = r(ub)  if G==5
sum corrpredRPMCRRA, detail
replace graphEPV = r(mean)*100 if G==7
ci mean corrpredRPMCRRA, level(95)
replace low = r(lb)   if G==7
replace high = r(ub)  if G==7
sum corrpredRPMCARA, detail
replace graphEPV = r(mean)*100 if G==9
ci mean corrpredRPMCARA, level(95)
replace low = r(lb)   if G==9
replace high = r(ub)  if G==9
keep if G<10
replace low= low*100
replace high =high*100
#delimit ;
twoway 
(bar  graphEPV G if G ==1 ,lcolor(black)  fcolor(orange_red)  )
(bar  graphEPV G if G ==3 ,lcolor(black)  fcolor(gs5)  )
(bar  graphEPV G if G ==5 ,lcolor(black)  fcolor(gs8)  )
(bar  graphEPV G if G ==7 ,lcolor(black)  fcolor(gs12)  )
(bar  graphEPV G if G ==9 ,lcolor(black)  fcolor(gs15)  )
(rcap high   low G, lcolor(red)lwidth(thick))
,
  graphregion(color(white) fcolor(white) lcolor(white)  ) plotregion(fcolor(white) lcolor(white) )
 ytitle("Correctly Predicted Choices (%)" " ", size(large)) 
     ylabel(0(10)80, grid)
 xlabel(1 "TWT" 3"RUM-CRRA" 5"RUM-CARA" 7"RPM-CRRA" 9"RPM-CARA", noticks   )
xtitle("  ") yline(76.14, lpattern(dash) lcolor(red)lwidth(thick))
legend(off)  
 name(Figure2Left, replace) saving(Figure2Left, replace)
;#delimit cr
graph export Figure2Left.eps, as(eps) preview(on) replace
restore
